package com.idheima.zuoye.zuoye1;

import java.io.File;

public class Test {
    public static void delte(File  file){
        if (file== null|| !file.exists()){
            return;
        }
        if (file.isDirectory()){
        File[] files = file.listFiles();
            if (files != null){
                for (File f : files) {
                    delte(f);
                }
            }
        }
        boolean deleted = file.delete();
        if (deleted){
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }

        //把此if放到循环里面
        /*if (file== null && !file.exists() && file.isDirectory()){
            file.delete();
        }
         */

    }

    public static void main(String[] args) {
        File file = new File("D:\\a");
        delte(file);

    }
}
